package com.transpot.controller.money;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.transpot.entry.money.Stream;
import com.transpot.service.money.StreamService;
import com.transpot.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/stream")
public class StreamController {
    @Autowired
    private StreamService streamService;
    @GetMapping("/getAllStream")
    public R getAllStream(int current, int size) {
        Page<Stream> streamPage = new Page<>(current, size);
        LambdaQueryWrapper<Stream> streamLambdaQueryWrapper = new LambdaQueryWrapper<>();
        streamLambdaQueryWrapper.orderByDesc(Stream::getCreateTime);
        streamService.page(streamPage, streamLambdaQueryWrapper);
        return R.success(streamPage);
    }

    /**
     * 添加流水方法
     * @param stream
     * @return
     */
    @PostMapping("/addStream")
    public R addStream(@RequestBody Stream stream) {
        //设置添加时间为当前
        stream.setCreateTime(LocalDateTime.now());
        //调用mp的方法保存
        streamService.save(stream);
        return R.success();
    }
}
